package com.ruoyi.web.controller.supermarket;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.supermarket.domain.SupermarketStock;
import com.ruoyi.supermarket.service.ISupermarketStockService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 进货信息Controller
 * 
 * @author faye
 * @date 2024-05-28
 */
@RestController
@RequestMapping("/supermarket/stock")
public class SupermarketStockController extends BaseController
{
    @Autowired
    private ISupermarketStockService supermarketStockService;

    /**
     * 查询进货信息列表
     */
    @PreAuthorize("@ss.hasPermi('supermarket:stock:list')")
    @GetMapping("/list")
    public TableDataInfo list(SupermarketStock supermarketStock)
    {
        startPage();
        List<SupermarketStock> list = supermarketStockService.selectSupermarketStockList(supermarketStock);

        return getDataTable(list);
    }

    /**
     * 导出进货信息列表
     */
    @PreAuthorize("@ss.hasPermi('supermarket:stock:export')")
    @Log(title = "进货信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SupermarketStock supermarketStock)
    {
        List<SupermarketStock> list = supermarketStockService.selectSupermarketStockList(supermarketStock);
        ExcelUtil<SupermarketStock> util = new ExcelUtil<SupermarketStock>(SupermarketStock.class);
        util.exportExcel(response, list, "进货信息数据");
    }

    /**
     * 获取进货信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('supermarket:stock:query')")
    @GetMapping(value = "/{stockId}")
    public AjaxResult getInfo(@PathVariable("stockId") Long stockId)
    {
        return success(supermarketStockService.selectSupermarketStockByStockId(stockId));
    }

    /**
     * 新增进货信息
     */
    @PreAuthorize("@ss.hasPermi('supermarket:stock:add')")
    @Log(title = "进货信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SupermarketStock supermarketStock)
    {
        return toAjax(supermarketStockService.insertSupermarketStock(supermarketStock));
    }

    /**
     * 修改进货信息
     */
    @PreAuthorize("@ss.hasPermi('supermarket:stock:edit')")
    @Log(title = "进货信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SupermarketStock supermarketStock)
    {
        return toAjax(supermarketStockService.updateSupermarketStock(supermarketStock));
    }

    /**
     * 删除进货信息
     */
    @PreAuthorize("@ss.hasPermi('supermarket:stock:remove')")
    @Log(title = "进货信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{stockIds}")
    public AjaxResult remove(@PathVariable Long[] stockIds)
    {
        return toAjax(supermarketStockService.deleteSupermarketStockByStockIds(stockIds));
    }
}
